Don't throw away errors with `-p` arguments
authorAlex Crichton <alex@alexcrichton.com>
Fri, 20 May 2016 21:25:43 +0000 (14:25 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 20 May 2016 23:56:03 +0000 (16:56 -0700)
This was unfortunately ignoring errors which would helpfully tell you how to
rerun a command with a more precise specification.

Closes #2641

src/cargo/ops/cargo_compile.rs
tests/test_cargo_compile.rs
tests/test_cargo_overrides.rs

index d330ea3ce29884f93c8a43fe9e5f3afa5e331080..f7fff08a331968dbf5e555b991b1502977d3e69a 100644 (file)
@@ -167,23 +167,15 @@ pub fn compile_pkg<'a>(root_package: &Package,
                                   no_default_features))
     };
 
-    let mut invalid_spec = vec![];
-    let pkgids = if spec.len() > 0 {
-        spec.iter().filter_map(|p| {
-            match resolve_with_overrides.query(&p) {
-                Ok(p) => Some(p),
-                Err(..) => { invalid_spec.push(p.to_string()); None }
-            }
-        }).collect::<Vec<_>>()
+    let mut pkgids = Vec::new();
+    if spec.len() > 0 {
+        for p in spec {
+            pkgids.push(try!(resolve_with_overrides.query(&p)));
+        }
     } else {
-        vec![root_package.package_id()]
+        pkgids.push(root_package.package_id());
     };
 
-    if !spec.is_empty() && !invalid_spec.is_empty() {
-        bail!("could not find package matching spec `{}`",
-              invalid_spec.join(", "))
-    }
-
     let to_builds = try!(pkgids.iter().map(|id| {
         packages.get(id)
     }).collect::<CargoResult<Vec<_>>>());
index 58246eb04f418fae02dc23b358aaa1cd7dc4962e..e67c1fa61298506f733e1ea1a36cb6d450adad87 100644 (file)
@@ -2107,13 +2107,14 @@ test!(invalid_spec {
     p.build();
 
     assert_that(p.cargo_process("build").arg("-p").arg("notAValidDep"),
-                execs().with_status(101).with_stderr(&format!(
-                    "[ERROR] could not find package matching spec `notAValidDep`")));
+                execs().with_status(101).with_stderr("\
+[ERROR] package id specification `notAValidDep` matched no packages
+"));
 
     assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("notAValidDep"),
-                execs().with_status(101).with_stderr(&format!(
-                    "[ERROR] could not find package matching spec `notAValidDep`")));
-
+                execs().with_status(101).with_stderr("\
+[ERROR] package id specification `notAValidDep` matched no packages
+"));
 });
 
 test!(manifest_with_bom_is_ok {
index c9cd0134021ac1de648e930b76d64376390d1557..d10cbd959280c643e8c811f81f7306ea336d1f29 100644 (file)
@@ -526,3 +526,41 @@ error: overlapping replacement specifications found:
 both specifications match: foo v0.1.0 ([..])
 "));
 });
+
+test!(test_override_dep {
+    Package::new("foo", "0.1.0").publish();
+
+    let foo = git::repo(&paths::root().join("override"))
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", "pub fn foo() {}");
+    foo.build();
+
+    let p = project("local")
+        .file("Cargo.toml", &format!(r#"
+            [package]
+            name = "local"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+
+            [replace]
+            "foo:0.1.0" = {{ git = '{0}' }}
+        "#, foo.url()))
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("test").arg("-p").arg("foo"),
+                execs().with_status(101)
+                       .with_stderr_contains("\
+error: There are multiple `foo` packages in your project, and the [..]
+Please re-run this command with [..]
+  [..]#foo:0.1.0
+  [..]#foo:0.1.0
+"));
+});